/*
 * DefaultListModelWithIndividual.java
 *
 * Created on 11 de Dezembro de 2007, 23:57
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.ontoscheduler.ui;

import com.hp.hpl.jena.ontology.Individual;
import java.util.ArrayList;
import javax.swing.DefaultListModel;

/**
 *
 * @author joaoolavo
 */
public class DefaultListModelWithIndividual extends DefaultListModel {
    
    ArrayList individuals = new ArrayList();
    
    /**
     * Creates a new instance of DefaultListModelWithIndividual
     */
    public DefaultListModelWithIndividual() {
    }
    
    public Individual getIndividual(int pos){
        return (Individual) individuals.get(pos);
    }
    
    public Individual getIndividual(String name){
        for(int i = 0; i < individuals.size(); i++){
            if(((String)this.getElementAt(i)).equals(name))
                return (Individual) individuals.get(i);
        }
        return null;
    }
    
    public void addElement(Individual ind){
        individuals.add(ind);
        addElement(ind.getLabel(null));
    }
    
    public void addIndividual(Individual ind, int pos){
        individuals.set(pos, ind);
    }
    
    public void removeElement(Individual ind){
        for(int i = 0; i < individuals.size(); i++){
            Individual v = (Individual) individuals.get(i);
            if(v.equals(ind)){
                individuals.remove(i);
                this.removeElementAt(i);
            }
        }
    }
}
